<template>
  <div>
    <edit-account @updateAccount="updateAccount" :ruleForm="ruleForm" :authorityList="authorityList" @sendModule_id="handleModule_id"></edit-account>
  </div>
</template>
<script>
import EditAccount from '@/views/account/account-cmp'
import {getModules, createUpdateAccount} from '@/api/operation'
import {ERR_OK} from '@/api/config'
import { parse } from 'path'
export default {
  data() {
    return {
      ruleForm: {
        admin_id: "",
        admin_account: "",
        admin_password: "",
        admin_confirm_password: "",
        admin_name: "",
        admin_phone: "",
        auth: ""
      },
      authorityList: [],
      auth: []
    }
  },
  components: {
    EditAccount
  },
  created() {
    let accountDetail = JSON.parse(localStorage.getItem('ACCOUNT_DETAIL'))
    console.log(accountDetail)
    this.ruleForm.admin_id = accountDetail.id
    this.ruleForm.admin_account = accountDetail.admin_account
    this.ruleForm.admin_password = accountDetail.admin_password
    this.ruleForm.admin_name = accountDetail.admin_name
    this.ruleForm.admin_phone = accountDetail.admin_phone
    this._getModules()
  },
  methods: {
    updateAccount(params) {
      params.auth = JSON.stringify(this.auth)

      console.log(params)
      this._createUpdateAccount(params)
    },
    handleModule_id(val) {
      // console.log(val)
      this.auth.push({"admin_id": this.$route.params.id, "module_id": val.mod_id})
      val.children.forEach((item) => {
        this.auth.push({"admin_id": this.$route.params.id, "module_id": item.mod_id})
      })
      
      console.log(this.auth)
    },
    _getModules() {
      getModules()
        .then((res) => {
          if (res.code == ERR_OK) {
            this.authorityList = res.list
          }
        })
        .catch((err) => {
          console.log(err)
        })
    },
    _createUpdateAccount(params) {
      createUpdateAccount(params)
        .then((res) => {
          if (res.code == ERR_OK) {
            console.log(res)
          }
        })
        .catch((err) => {
          console.log(err)
        })
    }
  }
}
</script>
<style lang="scss" scoped>
</style>